import { ColumnGroupType, ColumnType } from "antd/es/table"

import { IProxyWithdrawItemResponse } from "@/api/funds/types"
import Copy from "@/components/business/copy/Copy"
import TooltipText from "@/components/common/tooltipText"
import { DICT_DEFAULT_CONFIG } from "@/constants/dict"
import { handleNumber } from "@/utils/util"

const proxyPatchAddAdjustType = [
	{
		code: 1,
		userType: 1,
		value: 1,
		description: "funds.proxy_member_funds_record.agent_deposit_backstage"
	},
	{
		code: 2,
		userType: 1,
		value: 2,
		description: "funds.proxy_member_funds_record.agent_withraw_backstage"
	},
	{
		code: 3,
		userType: 0,
		value: 1,
		description: "funds.proxy_member_funds_record.member_deposit_backstage"
	},
	{
		code: 4,
		userType: 0,
		value: 2,
		description: "funds.proxy_member_funds_record.member_withraw_backstage"
	}
]

const Funds = (
	newFormat: (arg: string) => string,
	_getFromDic: (arg: string, strictlyLabel?: boolean) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	eventId: {
		key: "eventId",
		align: "center",
		dataIndex: "eventId",
		title: newFormat("funds.order_no"),
		render: (text: string) => (text ? <Copy title={text} /> : "-"),
		width: 280
	},
	orderNo: {
		key: "orderNo",
		align: "center",
		dataIndex: "orderNo",
		title: newFormat("funds.order_no"),
		render: (text: string) => <Copy title={text} />,
		width: 280
	},
	fundsNickName: {
		key: "nickName",
		align: "center",
		dataIndex: "nickName",
		title: newFormat("funds.capital_adjustment.member_nickname"),
		width: 280,
		render: (text: string) => text ?? "-"
	},
	thirdOrderNo: {
		key: "thirdOrderNo",
		align: "center",
		dataIndex: "thirdOrderNo",
		title: newFormat("funds.fund_audit.connect_three_order_no"),
		render: (text: string) => (text ? <Copy title={text} /> : "-"),
		width: 260
	},
	fundsUserName: {
		key: "userName",
		align: "center",
		dataIndex: "userName",
		title: newFormat("funds.user_name"),
		render: (text: string) => <Copy title={text} />,
		width: 200
	},
	realName: {
		key: "realName",
		align: "center",
		dataIndex: "realName",
		title: newFormat("funds.proxy_member_funds_record.real_name"),
		width: 120,
		render: (text: string) => text ?? "-"
	},
	merchantName: {
		key: "merchantName",
		align: "center",
		dataIndex: "merchantName",
		title: newFormat("common.belong_merchant"),
		width: 130,
		render: (text: string) => text ?? "-"
	},
	rebateAmount: {
		key: "rebateAmount",
		align: "center",
		dataIndex: "rebateAmount",
		title: newFormat("funds.proxy_member_funds_record.rebate_amount"),
		width: 180,
		render: (text: string, record: { symbolUsdt: string }) => handleNumber(record.symbolUsdt, text)
	},
	rebateRealAmount: {
		key: "rebateAmount",
		align: "center",
		dataIndex: "rebateAmount",
		title: newFormat("funds.proxy_member_funds_record.real_rebate_amount"),
		width: 180,
		render: (text: string, record: { symbolUsdt: string }) => handleNumber(record.symbolUsdt, text)
	},
	payoutTime: {
		key: "payoutTime",
		align: "center",
		dataIndex: "payoutTime",
		title: newFormat("funds.proxy_member_funds_record.created_at_time"),
		width: 200
	},
	appTypeStr: {
		key: "appTypeStr",
		align: "center",
		dataIndex: "appTypeStr",
		title: newFormat("funds.proxy_member_funds_record.app_type"),
		width: 130,
		render: (text: string) => text ?? "-"
	},
	rebateBettingTime: {
		key: "createAt2",
		align: "center",
		dataIndex: "createAt2",
		title: newFormat("label.bet.createAt"),
		width: 100,
		render: (text: string) => text ?? "-"
	},
	rebateBettingParentProxy: {
		dataIndex: "parentProxyName",
		title: newFormat("funds.proxy_member_funds_record.parent_proxy_name"),
		width: 120,
		align: "center",
		render: (text: string) => text ?? "-"
	},
	rebateRate: {
		dataIndex: "rebateRate",
		title: newFormat("funds.proxy_member_funds_record.rebate_ratio"),
		width: 120,
		align: "center",
		render: (text: string) => <p>{text}%</p> ?? "-"
	},

	appType: {
		key: "appType",
		align: "center",
		dataIndex: "appType",
		title: newFormat("funds.proxy_member_funds_record.app_type"),
		width: 130,
		render: _getFromDic("loginDeviceType", false)
	},
	orderStatusStr: {
		key: "orderStatusStr",
		align: "center",
		dataIndex: "orderStatusStr",
		title: newFormat("funds.proxy_member_funds_record.order_status"),
		width: 100,
		render: (text: string) => text ?? "-"
	},
	orderStatus: {
		key: "orderStatus",
		align: "center",
		dataIndex: "orderStatus",
		title: newFormat("funds.proxy_member_funds_record.order_status"),
		width: 120,
		render: _getFromDic("withdrawOrderStatus", false)
	},
	clientStatusStr: {
		key: "clientStatusStr",
		align: "center",
		dataIndex: "clientStatusStr",
		title: newFormat("funds.proxy_member_funds_record.client_state"),
		width: 100,
		render: (text: string) => text ?? "-"
	},
	clientStatus: {
		key: "clientStatus",
		align: "center",
		dataIndex: "clientStatus",
		title: newFormat("funds.proxy_member_funds_record.client_state"),
		width: 150,
		render: _getFromDic("withdrawClientStatus", false)
	},
	depositIp: {
		key: "ip",
		align: "center",
		dataIndex: "ip",
		title: (
			<>
				{newFormat("funds.proxy_member_funds_record.deposit_ip")}
				<br />
				{newFormat("funds.wind_control_level")}
			</>
		),
		width: 180,
		render: (text: string, record: { ip: string; ipWindControl: string }) => {
			return (
				<>
					{text || "-"}
					<br />
					<span className="redColor">
						{newFormat("funds.wind_control_level")}：{record.ipWindControl || "-"}
					</span>
				</>
			)
		}
	},
	withdrawalIp: {
		key: "ip",
		align: "center",
		dataIndex: "ip",
		title: (
			<>
				{newFormat("funds.proxy_member_funds_record.withdrawal_ip")}
				<br />
				{newFormat("funds.wind_control_level")}
			</>
		),
		width: 180,
		render: (text: string, record: { ip: string; ipWindControl: string }) => {
			return (
				<>
					{text || "-"}
					<br />
					<span className="redColor">
						{newFormat("funds.wind_control_level")}：{record.ipWindControl || "-"}
					</span>
				</>
			)
		}
	},
	fundsDeviceNo: {
		key: "deviceNo",
		align: "center",
		dataIndex: "deviceNo",
		title: (
			<>
				{newFormat("funds.proxy_member_funds_record.deposit_terminal_number")}
				<br />
				{newFormat("funds.wind_control_level")}
			</>
		),
		width: 300,
		render: (text: string, record: { ip: string; deviceNoWindControl: string }) => {
			return (
				<>
					<TooltipText text={text || "-"} />
					<span className="redColor">
						{newFormat("funds.wind_control_level")}：{record.deviceNoWindControl || "-"}
					</span>
				</>
			)
		}
	},
	withdrawDeviceNo: {
		key: "deviceNo",
		align: "center",
		dataIndex: "deviceNo",
		title: (
			<>
				{newFormat("funds.proxy_member_funds_record.withdraw_device_no")}
				<br />
				{newFormat("funds.wind_control_level")}
			</>
		),
		width: 180,
		render: (text: string, record: { ip: string; deviceNoWindControl: string }) => {
			return (
				<>
					<TooltipText text={text || "-"} />
					<span className="redColor">
						{newFormat("funds.wind_control_level")}：{record.deviceNoWindControl || "-"}
					</span>
				</>
			)
		}
	},
	payMerchantName: {
		key: "payMerchantName",
		align: "center",
		dataIndex: "payMerchantName",
		title: newFormat("funds.thirdPeymentChannelConfig.payment_merchant_name"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	payTypeStr: {
		key: "payTypeStr",
		align: "center",
		dataIndex: "payTypeStr",
		title: newFormat("funds.pay_type"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	withdrawType: {
		key: "withdrawType",
		align: "center",
		dataIndex: "withdrawType",
		title: newFormat("funds.pay_type"),
		width: 150,
		render: (type: number) => {
			return (
				<span>
					{type === 1
						? newFormat("funds.proxy_member_funds_record.brank_card")
						: type === 2
						? newFormat("funds.proxy_member_funds_record.virtual_currency")
						: "-"}
				</span>
			)
		}
	},
	currency: {
		key: "currency",
		align: "center",
		dataIndex: "currency",
		title: newFormat("funds.fund_audit.pay_currency"),
		width: 130,
		render: (text: string) => text ?? "-"
	},
	currencyType: {
		key: "currencyTypesList",
		align: "center",
		dataIndex: "currencyTypesList",
		title: newFormat("label.currency"),
		width: 120,
		render: (list: string[]) => {
			return list.length === 0
				? "-"
				: list.reduce((pre, cur) => {
						return pre + (pre === "" ? "" : ", ") + cur
				  }, "")
		}
	},
	channelName: {
		key: "channelName",
		align: "center",
		dataIndex: "channelName",
		title: newFormat("funds.channel_name"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	withdrawAccount: {
		key: "withdrawAccount",
		align: "center",
		dataIndex: "withdrawAccount",
		title: newFormat("funds.proxy_member_funds_record.withdraw_account"),
		width: 150,
		render: (_, record: IProxyWithdrawItemResponse) => {
			return (
				<span>
					{record.withdrawType === 1 ? record.bankcardNo || "--" : record.withdrawType === 2 ? record.usdtAddress || "-" : "-"}
				</span>
			)
		}
	},
	withdrawInfo: {
		key: "withdrawInfo",
		align: "center",
		dataIndex: "withdrawInfo",
		title: newFormat("funds.proxy_member_funds_record.withdraw_info"),
		width: 150,
		render: (_, record: IProxyWithdrawItemResponse) => {
			return (
				<span>
					{record.withdrawType === 1 ? (
						<>
							{record.bankName || "-"} <br /> {record.realName || "-"}
						</>
					) : record.withdrawType === 2 ? (
						<>
							{record.currency || "-"} <br /> {record.usdtType === 3 ? "TRC20" : record.usdtType === 2 ? "ERC20" : "-"}
						</>
					) : (
						"-"
					)}
				</span>
			)
		}
	},
	orderAmountUsdt: {
		key: "orderAmountUsdt",
		align: "center",
		dataIndex: "orderAmountUsdt",
		title: newFormat("funds.fund_audit.order_save_money_usdt"),
		width: 180,
		render: (text: string, record: { symbolUsdt: string }) => handleNumber(record.symbolUsdt, text)
	},
	withdrawOrderAmountUsdt: {
		key: "orderAmountUsdt",
		align: "center",
		dataIndex: "orderAmountUsdt",
		title: newFormat("funds.proxy_member_funds_record.withdraw_order_amount_usdt"),
		width: 180,
		render: (text: string, record: { symbolUsdt: string }) => handleNumber(record.symbolUsdt, text)
	},
	orderAmountCny: {
		key: "orderAmountCny",
		align: "center",
		dataIndex: "orderAmountCny",
		title: newFormat("funds.fund_audit.order_save_money_cny"),
		width: 180,
		render: (text: string, record: { symbolCny: string }) => handleNumber(record.symbolCny, text)
	},
	withdrawOrderAmountCny: {
		key: "orderAmountCny",
		align: "center",
		dataIndex: "orderAmountCny",
		title: newFormat("funds.proxy_member_funds_record.withdraw_order_amount_cny"),
		width: 180,
		render: (text: string, record: { symbolCny: string }) => handleNumber(record.symbolCny, text)
	},
	realAmountUsdt: {
		key: "realAmountUsdt",
		align: "center",
		dataIndex: "realAmountUsdt",
		title: newFormat("funds.fund_audit.real_record_money_usdt"),
		width: 180,
		render: (text: string, record: { symbolUsdt: string }) => handleNumber(record.symbolUsdt, text)
	},
	realAmountCny: {
		key: "realAmountCny",
		align: "center",
		dataIndex: "realAmountCny",
		title: newFormat("funds.fund_audit.real_record_money_cny"),
		width: 180,
		render: (text: string, record: { symbolCny: string }) => handleNumber(record.symbolCny, text)
	},
	eventTime: {
		key: "eventTime",
		align: "center",
		dataIndex: "eventTime",
		title: newFormat("funds.apply_time"),
		width: 200,
		render: (text: string) => text ?? "-"
	},
	payTime: {
		key: "payTime",
		align: "center",
		dataIndex: "payTime",
		title: newFormat("funds.proxy_member_funds_record.arrive_time"),
		width: 200,
		render: (text: string) => text ?? "-"
	},
	remark: {
		key: "remark",
		align: "center",
		dataIndex: "remark",
		title: newFormat("common.remark"),
		width: 200,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	withdrawRemark: {
		key: "remark",
		align: "center",
		dataIndex: "remark",
		title: newFormat("funds.proxy_member_funds_record.audit_desc"),
		width: 200,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	confirmClientDesc: {
		key: "confirmClientDesc",
		align: "center",
		dataIndex: "confirmClientDesc",
		title: newFormat("funds.proxy_member_funds_record.audit_client_desc"),
		width: 200,
		render: (text: string) => (text ? <TooltipText text={text} /> : "-")
	},
	backTopProxyName: {
		key: "topProxyName",
		align: "center",
		dataIndex: "topProxyName",
		title: newFormat("funds.proxy_member_funds_record.top_proxy_name"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	backParentProxyName: {
		key: "parentProxyName",
		align: "center",
		dataIndex: "parentProxyName",
		title: newFormat("funds.proxy_member_funds_record.parent_proxy_name"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	backOrderStatus: {
		key: "orderStatus",
		align: "center",
		dataIndex: "orderStatus",
		title: newFormat("funds.proxy_member_funds_record.order_status"),
		width: 100,
		render: (text: string, record: any) => {
			const data = Object.entries(DICT_DEFAULT_CONFIG.patchAdjustStatus)
			const options = data.map(item => ({ value: item[1].value, label: newFormat(item[1].label) }))
			let context: string = "-"
			options.forEach(option => {
				if (option.value == record.orderStatus) context = option.label
			})
			return <div>{context}</div>
		}
	},
	backAdjustType: {
		key: "adjustType",
		align: "center",
		dataIndex: "adjustType",
		title: newFormat("funds.proxy_member_funds_record.adjust_type"),
		width: 160,
		render: (text: string, record: any) => {
			let context: string = "-"
			proxyPatchAddAdjustType.forEach(option => {
				if (record.userType === option.userType && record.adjustType === option.value) context = option.description
			})
			return <div>{newFormat(context)}</div>
		}
	},
	backAdjustAmount: {
		key: "adjustAmount",
		align: "center",
		dataIndex: "adjustAmount",
		title: newFormat("funds.proxy_member_funds_record.adjust_amount"),
		width: 180,
		render: (text: string, record: { currency: string }) => handleNumber(record.currency, text)
	},
	backImageAddress: {
		key: "imageAddress",
		align: "center",
		dataIndex: "imageAddress",
		title: newFormat("funds.proxy_member_funds_record.annex_file"),
		width: 180
	},
	backOperator: {
		key: "operator",
		align: "center",
		dataIndex: "operator",
		title: newFormat("funds.proxy_member_funds_record.proposer"),
		width: 150,
		render: (text: string) => text ?? "-"
	},
	backApplyTime: {
		key: "createdAt",
		align: "center",
		dataIndex: "createdAt",
		title: newFormat("funds.apply_time"),
		width: 160,
		render: (text: string) => text ?? "-"
	},
	backArriveTime: {
		key: "audit2Time",
		align: "center",
		dataIndex: "audit2Time",
		title: newFormat("funds.proxy_member_funds_record.arrive_time"),
		width: 160,
		render: (text: string) => text ?? "-"
	},
	backRemark: {
		key: "remark",
		align: "center",
		dataIndex: "remark",
		title: newFormat("common.remark"),
		width: 220,
		render: (text: string) => text ?? "-"
	}
})
export default Funds
